<?php
if (!defined('INPOL')) return2();
$parse=$Lang;
$parse['page']=$page;
$parse['action']='add';
$parse['empty_selected']=' selected="selected"';
$parse['button_lang']=$Lang['add'];
$parse['button_click']='newPolicyPost();';
$parse['selects_disabled']='';

$parse['ins_comps']='';
$parse['nr_value']='';
$tqry=$sql->query("SELECT id, name, abbr FROM insurance_companies;");
while($otype=$sql->fetch_array($tqry))
{
    $parse['ins_comps'].='<option value="'.$otype['id'].'">'.$otype['abbr'].'</option>';
}
$parse['ins_types']='';
$parse['statuses']='';
$parse['takers']='';
$parse['owners']='';
$parse['subscribers']='';
$parse['init_js']='initAddPolicy();';
$parse['payment_button']='<font color="red">'.$Lang['payments_later'].'</font>';
$iqry=$sql->query("SELECT id, name FROM ins_type");
while($ins_type=$sql->fetch_array($iqry))
{
    $parse['ins_types'].='<option value="'.$ins_type['id'].'">'.$ins_type['name'].'</option>';
}


$iqry=$sql->query("SELECT id, name FROM pol_status");
while($ins_type=$sql->fetch_array($iqry))
{
    $parse['statuses'].='<option value="'.$ins_type['id'].'">'.$ins_type['name'].'</option>';
}

$tqry=$sql->query("SELECT id, name, code, address FROM clients ORDER BY name ASC");
while($taker=$sql->fetch_array($tqry))
{
    $taker['name']=str_replace("&","&amp;", $taker['name']);
    $parse['takers'].='<option value="'.$taker['id'].'">'.$taker['name'].' | '.$taker['code'].' | '.$taker['address'].'</option>';
}
$parse['owners']=$parse['subscribers']=$parse['takers'];
$parse['obj_types1']='';
$parse['obj_types2']='';
$otqry=$sql->query("SELECT id, name FROM object_type;");
while($otype1=$sql->fetch_array($otqry))
{
    $parse['obj_types1'].='<option value="'.$otype1['id'].'">'.$otype1['name'].'</option>';
}
$parse['obj_types2']=$parse['obj_types1'];
$parse['tl_codes']='';
$octa_codes_qry=$sql->query("SELECT id, code, name FROM octa_codes");
while($tl_codes=$sql->fetch_array($octa_codes_qry))
{
    $parse['tl_codes'].='<option value="'.$tl_codes['id'].'">'.$tl_codes['code'].' | '.$tl_codes['name'].'</option>';
}

$parse['octa_examples']='';
$octa_exmpl_qry=$sql->query("SELECT id,code, name FROM octa_examples;");
while($exmpl=$sql->fetch_array($octa_exmpl_qry))
{
    $parse['octa_examples'].= '<option value="'.$exmpl['id'].'">'.$exmpl['code'].' | '.$exmpl['name'].'</option>';
}
$parse['octa_discountss']='';
$octa_dsc_qry=$sql->query("SELECT id,code, name FROM octa_discounts;");
while($dsc=$sql->fetch_array())
{
    $parse['octa_discountss'].= '<option value="'.$dsc['id'].'">'.$dsc['code'].' | '.$dsc['name'].'</option>';
}

$parse['val_territories']='';
$valtqry=$sql->query("SELECT id, name FROM validity_territory;");
while($terr=$sql->fetch_array($valtqry))
{
    $parse['val_territories'].= '<option value="'.$terr['id'].'">'.$terr['name'].'</option>';
}            
$parse['currencies']='';
$curr_qry=$sql->query("SELECT id, name FROM currency");
while($curr=$sql->fetch_array($curr_qry))
{
    $parse['currencies'].= '<option value="'.$curr['id'].'">'.$curr['name'].'</option>';
}
$parse['brokers']='';
$brokers=$sql->query('SELECT id, name FROM brokers');
while($broker=$sql->fetch_array($brokers))
{
    $parse['brokers'].= '<option value="'.$broker['id'].'">'.$broker['name'].'</option>';
}
$parse['employees']='';
$emp_qry=$sql->query('SELECT id, name, user FROM employees');
while($emp=$sql->fetch_array($emp_qry))
{
    $selected=$emp['user']==$user->getUser()?'selected="selected"':'';
    $parse['employees'].= '<option value="'.$emp['id'].'"'.$selected.'>'.$emp['name'].'</option>';
}
$tpl->parsetemplate('policies',$parse);
?>